from rest_framework import serializers  
from .models import Submission, RelatedForm, CustomUser, Task, SubTask, AttachedTask, Message  
  
class SubmissionSerializer(serializers.ModelSerializer):  
    class Meta:  
        model = Submission  
        fields = '__all__'  # 包含所有字段
		
class RelatedFormSerializer(serializers.ModelSerializer):  
    class Meta:  
        model = RelatedForm  
        fields = ['progress_description', 'progress', 'original_form']
		
class CustomUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = CustomUser
        fields = ['id','username', 'company', 'department', 'position','custom_id','password']

class TaskSerializer(serializers.ModelSerializer):
    class Meta:
        model = Task
        fields = ['task_id', 'created_by']

class SubTaskSerializer(serializers.ModelSerializer):
    responsible_user = CustomUserSerializer(read_only=True)
    created_by = CustomUserSerializer(read_only=True)

    class Meta:
        model = SubTask
        fields = ['subtask_id', 'task', 'responsible_user', 'created_by', 'description', 'progress', 'importance']

class AttachedTaskSerializer(serializers.ModelSerializer):
    responsible_user = CustomUserSerializer(read_only=True)
    subtask = SubTaskSerializer(read_only=True)

    class Meta:
        model = AttachedTask
        fields = ['attached_task_id', 'subtask', 'responsible_user', 'description', 'progress', 'importance']
		
		
class MessageSerializer(serializers.ModelSerializer):
    sender = CustomUserSerializer(read_only=True)
    receiver = CustomUserSerializer(read_only=True)
 
    class Meta:
        model = Message
        fields = ['id', 'sender', 'receiver', 'text', 'image', 'file', 'audio', 'timestamp']